﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _14_List集合_Lambda表达式2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Random random = new Random();
            List<Student> students = new List<Student>();
            //添加学生信息
            students.Add(new Student("坤坤", "语文", random.Next(0, 101)));
            students.Add(new Student("坤坤", "数学", random.Next(0, 101)));
            students.Add(new Student("坤坤", "英语", random.Next(0, 101)));

            students.Add(new Student("王德发", "语文", random.Next(0, 101)));
            students.Add(new Student("王德发", "数学", random.Next(0, 101)));
            students.Add(new Student("王德发", "英语", random.Next(0, 101)));

            students.Add(new Student("龙傲天", "语文", random.Next(0, 101)));
            students.Add(new Student("龙傲天", "数学", random.Next(0, 101)));
            students.Add(new Student("龙傲天", "英语", random.Next(0, 101)));



            //去重获取所有学生的姓名
            List<string> names = students.Select(item => item.Name).Distinct().ToList();
            //遍历每一个学生： 平局分数 与 总分数
            foreach (var name in names)
            {
                List<Student> student = students.Where(item => item.Name == name).ToList();
                Console.WriteLine("{0}-平均分：{1:0.00}", name, student.Average(item => item.Score));
                Console.WriteLine("{0}-总分：{1}",name,student.Sum(item => item.Score));
                Console.WriteLine("==================================");
            }

            //求全班同学的语文平局分
            double avg = students.Where(item => item.Subject == "语文").Average(item => item.Score);
            Console.WriteLine("全班同学的语文平均分：{0:0.00}", avg);



            Console.Read();
        }
    }
}
